#include <iostream>
#include <stack>
#include <queue>
using namespace std;

class Queue {
public:
	Queue()  { }
	~Queue() { }

	void push(int v) {
		s1.push(v);
	}

	int pop() {
		if (s2.size() <= 0) {
			while (s1.size() > 0) {
				int t = s1.top();
				s2.push(t);
				s1.pop();
			}
		}

		if (s2.size() <= 0) {
			cout<<"empty queue"<<endl;
			return -1;
		}

		int r = s2.top();
		s2.pop();

		return r;
	}

private:
	stack<int> s1;
	stack<int> s2;
};

class Stack {
public:
	Stack() { }
	~Stack() { }

	void push(int v) {
		if (q1.size() > 0)
			q1.push(v);
		else if (q2.size() > 0)
			q2.push(v);
		else
			q1.push(v);
	}


	int pop() {
		if (q1.size() > 0) {
			while (q1.size() > 1) {
				int r = q1.front();
				q2.push(r);
				q1.pop();
			}

			int r = q1.front();
			q1.pop();

			return r;
		}
		else if (q2.size() > 0) {			
			while (q2.size() > 1) {
				int r = q2.front();
				q1.push(r);
				q2.pop();
			}

			int r = q2.front();
			q2.pop();

			return r;
		}
		else {
			cout<<"empty stack"<<endl;
			return -1;
		}
	}

private:
	queue<int> q1;
	queue<int> q2;
};

//int main() {
//	//Queue q;
//	//cout<<q.pop()<<endl;
//	//q.push(1);
//	//q.push(2);
//	//q.push(3);
//	//q.push(4);
//	//cout<<q.pop()<<endl;
//	//cout<<q.pop()<<endl;
//	//cout<<q.pop()<<endl;
//	//cout<<q.pop()<<endl;
//	//cout<<q.pop()<<endl;
//
//	Stack s;
//	cout<<s.pop()<<endl;
//	s.push(1);
//	s.push(2);
//	s.push(3);
//	s.push(4);
//	cout<<s.pop()<<endl;
//	cout<<s.pop()<<endl;
//	cout<<s.pop()<<endl;
//	cout<<s.pop()<<endl;
//	cout<<s.pop()<<endl;
//
//	return 0;
//}